package com.ruoyi.web.controller.ERP;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.ERP.MaterialDataErp;
import com.ruoyi.system.domain.ERP.MesOperationsErpDTO;
import com.ruoyi.system.domain.ERP.ProdPlanErpDTO;
import com.ruoyi.system.domain.base.BaseBomDTO;
import com.ruoyi.system.service.IBaseBomService;
import com.ruoyi.system.service.IBaseMaterialService;
import com.ruoyi.system.service.IProdPlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description: erp 接口相关
 * @author: zhengxiong.jiang
 * @createDate: 2023/3/8
 * @version: 1.0
 */
@Api(tags = "erp接口api")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/erp" )
public class ErpController {

    @Autowired
    private IBaseMaterialService iBaseMaterialService;
    @Autowired
    private IBaseBomService iBaseBomService;
    @Autowired
    private IProdPlanService prodPlanService;


    @GetMapping("/materialTypeSync")
    @ApiOperation(value = "物料主类型同步")
    public AjaxResult materialTypeSync() {
        return AjaxResult.success(iBaseMaterialService.materialTypeSync());
    }

    @GetMapping("/getMaterial")
    @ApiOperation(value = "物料主数据同步mom>wms")
    public AjaxResult getMaterial() {
        return AjaxResult.success(iBaseMaterialService.material());
    }

    @PostMapping("/materialSync")
    @ApiOperation(value = "物料主数据同步")
    public AjaxResult materialSync(@RequestBody List<MaterialDataErp> list) {
        return AjaxResult.success(iBaseMaterialService.materialSync(list));
    }

    @PostMapping("/materialDeleteSync")
    @ApiOperation(value = "物料主数据删除同步")
    public AjaxResult materialDeleteSync(@RequestBody List<String> list) {
        return AjaxResult.success(iBaseMaterialService.materialDeleteSync(list));
    }

    @PostMapping("/BomInfoSync")
    @ApiOperation(value = "BOM数据同步")
    public AjaxResult BomInfoSync(@RequestBody List<BaseBomDTO> list) {
        return AjaxResult.success(iBaseBomService.BomInfoSync(list));
    }

    @PostMapping("/orderSync")
    @ApiOperation(value = "生产工单数据同步")
    public AjaxResult orderSync(@RequestBody List<ProdPlanErpDTO> list) {
        return AjaxResult.success(prodPlanService.orderSync(list));
    }

    @PostMapping("/getOrderStatus")
    @ApiOperation(value = "生产计划工单状态查询")
    public AjaxResult getOrderStatus(@RequestBody ProdPlanErpDTO dto) {
        return AjaxResult.success(prodPlanService.getOrderStatus(dto));
    }

    @GetMapping("/getDepts")
    @ApiOperation(value = "获取部门信息")
    public AjaxResult getDepts() {
        iBaseBomService.getDepts();
        return AjaxResult.success();
    }

    @GetMapping("/getUsers")
    @ApiOperation(value = "获取用户信息")
    public AjaxResult getUsers() {
        iBaseBomService.getUsers();
        return AjaxResult.success();
    }


    @PostMapping("/mesopSync")
    @ApiOperation(value = "工艺数据同步")
    public AjaxResult mesopSync(@RequestBody List<MesOperationsErpDTO> list) {
        return AjaxResult.success(iBaseMaterialService.mesopSync(list));
    }

    @GetMapping("/getCustomer")
    @ApiOperation(value = "获取客户信息")
    public AjaxResult getCustomer() {
        return AjaxResult.success(iBaseBomService.getCustomer());
    }

    @GetMapping("/getSupplier")
    @ApiOperation(value = "获取供应商信息")
    public AjaxResult getSupplier() {
        return AjaxResult.success(iBaseBomService.getSupplier());
    }

}
